

*patent class to cfda

use "$data\employee_cfda", clear
ren iris emp_num_2019
merge m:1 emp_num_2019 using "$rawdata\emp_num_xwalk", keep(1 3) nogen
ren emp_num_2018 iris_employee_number
drop if iris_employee_number==""
save "$data\employee_cfda_2018", replace

use "$data\patent_umetrics", clear

merge m:1 patnum using "N:\GrpHOBAHE\approved_import_requests\Alex_2021-05-27\Patents_Tania_v2", keepus(cpc*) keep(1 3) nogen

joinby iris_employee_number using "$data\employee_cfda_2018"

drop if cpc_class == ""
collapse (sum) proportion, by(cpc_class cfda)

bysort cpc_class: egen temp=sum(proportion)
gen share=proportion/temp

merge m:1 cfda using "$data/matching/cfda_shocks", keep(1 3) nogen

drop if nshock==2 | nshock==.
bysort cpc_class: egen temp2=sum(nshock)
drop if temp2>0 & nshock==0

gsort cpc_class -share
by cpc_class: gen count=_n
drop if count>1

keep cpc_class nshock year_shock

save "$data\placebo_patent", replace

use "N:\GrpHOBAHE\approved_import_requests\Alex_2021-05-27\Patents_Tania_v2", clear
keep if fyear>2000

gen npatent=1
ren fyear year
collapse (sum) npatent, by (cpc_class year)
drop if cpc_class==""

egen cpc_class_num= group(cpc_class)
tsset cpc_class_num year
tsfill, full
replace npatent=0 if npatent==.

merge m:1 cpc_class using "$data\placebo_patent", keep(1 3) nogen

gen tau=year-year_shock
replace tau=-1 if tau==.
forv i=13(-1)1 {
	gen byte periodm`i'=(tau==-`i')
}

forv i=0/15 {
gen byte period`i' = (tau==`i')
}
gen periodm7b=(tau<=-7)
gen period7a=(tau>=7)
gen byte post=(tau>0)
gen lognpatent=log(npatent+1)
bysort cpc_class_num: egen totalnpatent=sum(npatent)

eststo clear

eststo: reghdfe lognpatent periodm7b periodm6-periodm1 period1-period6 period7a  if nshock!=., a(year cpc_class_num) vce(cluster cpc_class)

esttab using "$data\results\pretrend\march2021\eventstudy_placebo.csv", replace numbers label nogaps r2 ar2 star(* 0.1 ** 0.05 *** 0.01) b(%8.4f) se(%8.4f)


